package com.zhijiang.hospital.controller;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.excel.EasyExcel;
import com.zhijiang.hospital.entity.dto.InpatientPerformanceEvaluationDto;
import com.zhijiang.hospital.service.InpatientPerformanceEvaluationService;
import com.zhijiang.util.BaseQuery;
import com.zhijiang.util.Result;
import com.zhijiang.util.TimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital-data
 * @description
 * @date 2022-10-25 11:33:59
 */
@Slf4j
@Api(value = "住院绩效考核", tags = "住院绩效考核")
@RestController
@RequestMapping("Inpatient")
public class InpatientPerformanceEvaluationController {
    @Autowired
    private InpatientPerformanceEvaluationService inpatientPerformanceEvaluationService;


    @ApiOperation("分页查询所有的住院绩效考核")
    @ApiModelProperty(value = "分页查询所有的住院绩效考核")
    @PostMapping("selectAll")
    public Result loadPageList(@RequestBody BaseQuery baseQuery) {
        return Result.ok(inpatientPerformanceEvaluationService.loadPageList(TimeUtil.initBaseQuery(baseQuery)));
    }

    @ApiOperation("导出指定时间的住院绩效考核excel表格")
    @ApiModelProperty(value = "导出指定的住院绩效考核excel表格")
    @GetMapping("loadExcel")
    public void loadExcel(HttpServletResponse response) throws IOException {
        List<InpatientPerformanceEvaluationDto> list = inpatientPerformanceEvaluationService.findAll();
        log.error("导出指定的住院绩效考核数据", list);
        String title = "住院运行数据";
        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=" + RandomUtil.randomNumbers(4) + URLEncoder.encode("住院运行数据.xlsx", "utf-8"));
        //4. 创建输入、输出流
        EasyExcel.write(response.getOutputStream(), InpatientPerformanceEvaluationDto.class).sheet(title).doWrite(list);

    }

    //@ApiOperation("住院绩效考核DRG绩效总量")
    //@ApiModelProperty(value = "住院绩效考核DRG绩效总量",dataType = "住院绩效考核DRG绩效总量")
    //@GetMapping("findDddsWork")
    //public Result<List<String>> findTotalWork(){
    //    return Result.ok(inpatientPerformanceEvaluationService.findDddsWork());
    //}
    //@ApiOperation("住院绩效考核DRG绩效总量 周数据")
    //@ApiModelProperty(value = "住院绩效考核DRG绩效总量 周数据")
    //@GetMapping("findTotalWordOfMonth")
    //public  Result findTotalWordOfMonth(){
    //    return Result.ok(inpatientPerformanceEvaluationService.findDddsWorkOfMonth());
    //}
    //@ApiOperation("年度绩效考核对比")
    //@GetMapping("findDddsWorkOfYear")
    //public Result findTotalWordOfYear(){
    //    return Result.ok(inpatientPerformanceEvaluationService.findDddsWorkOfYear());
    //}
    @ApiOperation("获取今年的数据")
    @ApiModelProperty(value = "获取今年的数据")
    @GetMapping("getYearData")
    public Result getYearData() {
        List<InpatientPerformanceEvaluationDto> yearData = inpatientPerformanceEvaluationService.getYearData();
        return Result.ok(yearData);
    }


    @ApiOperation("获取去年的数据")
    @ApiModelProperty(value = "获取去年的数据")
    @GetMapping("getLastYearData")
    public Result getLastYearData() {
        List<InpatientPerformanceEvaluationDto> yearData = inpatientPerformanceEvaluationService.getLastYearData();
        return Result.ok(yearData);
    }


}
